//
//  HYMyBookingSeatDetailVC.m
//  Booking
//
//  Created by Maybe_文仔 on 2018/9/13.
//  Copyright © 2018年 Duntech. All rights reserved.
//

#import "HYMyBookingSeatDetailVC.h"
#import "MySeatBezierView.h"

@interface HYMyBookingSeatDetailVC ()<UIScrollViewDelegate>
@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *imageView;
@property (nonatomic, strong) MySeatBezierView *bezierView;
@property (nonatomic, strong) UIView *topView;
@property (nonatomic, strong) UILabel *myLocationLab;
@property (nonatomic, strong) UILabel *descripLab;
@property (nonatomic, strong) UILabel *lineLab;
@end

@implementation HYMyBookingSeatDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = NSLocalizedString(@"seatFloorPlan", nil);
    [self setupSubViews];
    // Do any additional setup after loading the view.
    
    
}

-(void)setupSubViews{
    [self.view addSubview:self.topView];
    [self.topView addSubview:self.lineLab];
    [self.topView addSubview:self.myLocationLab];
    [self.topView addSubview:self.descripLab];
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self.view);
        make.height.mas_equalTo(36);
    }];
    
    [self.lineLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self.topView);
        make.height.mas_equalTo(1);
    }];
    
    [self.myLocationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(self.topView.mas_left).mas_offset(10);
        make.size.mas_equalTo(CGSizeMake(13, 13));
    }];
    
    [self.descripLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.topView.mas_centerY);
        make.left.mas_equalTo(self.myLocationLab.mas_right).mas_offset(10);
    }];
    
    //缩放图
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.backgroundColor = KAPP_WHITE_COLOR;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView = scrollView;
    [self.view addSubview:scrollView];
    
    //底图
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"seat_app_bg"]];
    imageView.backgroundColor = KAPP_WHITE_COLOR;
    self.imageView = imageView;
    [scrollView addSubview:imageView];
    
    //画布
    MySeatBezierView *beView = [[MySeatBezierView alloc] initWithFrame:CGRectMake(0, 0, imageView.image.size.width, imageView.image.size.height)];
    beView.backgroundColor = [UIColor clearColor];
    beView.mySeatId = self.myBookingSeatModel.stationId;
    self.bezierView = beView;
    [imageView addSubview:beView];
    
    //重新规划大小
    CGFloat realW = imageView.image.size.width;
    CGFloat scaleMin = self.view.frame.size.width/realW;
    
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topView.mas_bottom);
        make.left.right.bottom.mas_equalTo(self.view);
    }];
    
    // 设置代理
    self.scrollView.delegate = self;
    
    // 设置缩放比例
    self.scrollView.maximumZoomScale = 2.0;
    self.scrollView.minimumZoomScale = scaleMin;
    self.scrollView.zoomScale = scaleMin;
}

#pragma mark -- 这个方法的返回值决定了要缩放的内容（返回值只能是UIScrollView的子控件）

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}

#pragma mark -- 懒加载

-(UIView *)topView{
    if (!_topView) {
        _topView = [UIView new];
        _topView.backgroundColor = KAPP_WHITE_COLOR;
    }
    return _topView;
}

-(UILabel *)myLocationLab{
    if (!_myLocationLab) {
        _myLocationLab = [UILabel new];
        _myLocationLab.backgroundColor = KAPP_THEME_COLOR;
        _myLocationLab.layerCornerRadius = 2;
    }
    return _myLocationLab;
}

-(UILabel *)descripLab{
    if (!_descripLab) {
        _descripLab = [UILabel new];
        _descripLab.text = NSLocalizedString(@"youAreHere", nil);
        _descripLab.font = KFont(15);
    }
    return _descripLab;
}

-(UILabel *)lineLab{
    if (!_lineLab) {
        _lineLab = [UILabel new];
        _lineLab.backgroundColor = KAPP_THEME_COLOR;
    }
    return _lineLab;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
